/*
 * Int16NumberFormatter.cpp
 *
 * Copyright 2012 Pieter Agten
 *
 * This file is part of tltgen.
 *
 * tltgen is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * tltgen is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with tltgen.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * @file   Int16NumberFormatter.cpp
 * @author Pieter Agten (pieter.agten@gmail.com)
 * @date   13 sep 2012
 */


#include <math.h>
#include <stdexcept>
#include <boost/lexical_cast.hpp>

#include "Int16NumberFormatter.hpp"

namespace tltgen {

  const std::string Int16NumberFormatter::format(double value) const
  {
    long intNumber = (long)floor(value + 0.5);
    if (intNumber < Int16NumberFormatter::MIN_VALUE || intNumber > Int16NumberFormatter::MAX_VALUE) {
      throw std::out_of_range("Value '" + boost::lexical_cast<std::string>(value) +
			      "' is out of range for an int16 number formatter.");
    }
    return boost::lexical_cast<std::string>(intNumber);
  }


}

